import {Map, List} from 'immutable';
import * as ChargeConstant from '../constants/ChargeConstant';

const initState = Map({
  apiRes: {},
  recordHistories: [],
  
});

export default function Message(state = initState, action) {
    
  switch (action.type) {
    case ChargeConstant.REQUEST_CHARGE_RECORD_HISTORY:
      let pageNo = action.pageNo;
      if (action.data.datas.list) {
        if (pageNo == 1) {
          state = state.set('recordHistories', action.data.datas.list);
        } else {
          let oldRecords = state.get('recordHistories');
          oldRecords = oldRecords.concat(action.data.datas.list); 
          state = state.set('recordHistories', oldRecords);
        }
      }
      state = state.set('apiRes', action.data);
      break;
  }
  return state;
}